package com.wkhyapp.lm.adapter;

import android.content.Context;
import android.view.View;
import android.widget.ImageView;

import com.wkhyapp.lm.R;
import com.wkhyapp.lm.adapter.base.HolderEntity;
import com.wkhyapp.lm.adapter.base.MirAdapter;
import com.wkhyapp.lm.utils.ImageLoadUtil;

import java.util.List;

/**
 * Created by fang on 2021/10/29.
 */

public class SelectImageApdater extends MirAdapter<String> {

    public SelectImageApdater.callBack mCallBack;
    public SelectImageApdater(Context context, List<String> mDatas, int itemLayoutId) {
        super(context, mDatas, itemLayoutId);
    }

    @Override
    public void convert(HolderEntity helper, final String item) {
        ImageView imageView = helper.getView(R.id.imageView);
        ImageView delete_iv = helper.getView(R.id.delete_iv);
        if("add".equals(item)){
            ImageLoadUtil.setImage_Normal(mContext,R.drawable.icon_add,imageView);
            imageView.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    mCallBack.add(item);
                }
            });
            delete_iv.setVisibility(View.GONE);
        }else{
            delete_iv.setVisibility(View.VISIBLE);
            ImageLoadUtil.setImage_Normal(mContext,item,imageView);
            delete_iv.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    mCallBack.delete(item);
                }
            });
        }
    }


    public void  setCallBack(SelectImageApdater.callBack callBack){
        this.mCallBack = callBack;
    }


    public interface  callBack{
        void add(String item);

        void delete(String item);
    }
}
